package com.dgut.service;

import com.dgut.mapper.UsersMapper;
import com.dgut.pojo.Users;
import com.dgut.pojo.UsersExample;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserService {

    @Resource
    private UsersMapper usersMapper;

    @Transactional(propagation = Propagation.REQUIRED,readOnly = true)
    public int login(String loginName, String password){
        //多条件容器
        UsersExample usersExample = new UsersExample();
        UsersExample.Criteria criteria = usersExample.createCriteria();
        //放参数进容器
        criteria.andLoginnameEqualTo(loginName);
        criteria.andPasswordEqualTo(password);
        //查询
        List<Users> users = usersMapper.selectByExample(usersExample);
        if (users.size()==1){
            return 1;
        }
        return 0;
    }

}
